package com.hbm.pojo;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="hbm_order")
public class Order {
	private int id;
	private String ordno;
	private double cost;
	private String status;

	private Customer customer;

	/**
	 * @param id
	 * @param ordno
	 * @param cost
	 * @param status
	 * @param customer_id
	 */
	public Order(int id, String ordno, double cost, String status) {
		super();
		this.id = id;
		this.ordno = ordno;
		this.cost = cost;
		this.status = status;
	}

	public Order(String ordno, double cost, String status) {
		super();
		this.ordno = ordno;
		this.cost = cost;
		this.status = status;
	}

	/**
	 * 
	 */
	public Order() {
		super();
	}
	

	@Id
	@GeneratedValue(generator="order_id",strategy=GenerationType.SEQUENCE)
	@SequenceGenerator(name="order_id",sequenceName="order_seq")
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(nullable=false,unique=true,length=18)
	public String getOrdno() {
		return ordno;
	}

	public void setOrdno(String ordno) {
		this.ordno = ordno;
	}

	@Column(length=11,scale=2)
	public double getCost() {
		return cost;
	}

	public void setCost(double cost) {
		this.cost = cost;
	}

	@Column
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@ManyToOne
	@JoinColumn(name="customer_id")
	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Order [id=").append(id).append(", ordno=").append(ordno).append(", cost=").append(cost)
				.append(", status=").append(status).append("]");
		return builder.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result + ((ordno == null) ? 0 : ordno.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Order other = (Order) obj;
		if (id != other.id)
			return false;
		if (ordno == null) {
			if (other.ordno != null)
				return false;
		} else if (!ordno.equals(other.ordno))
			return false;
		return true;
	}

}
